package com.shundr;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.shundr.base.BaseFragment;
import com.shundr.common.CommonWebViewActivity;
import com.shundr.common.InvitationActivity;
import com.shundr.common.http.CommonRequest;
import com.shundr.common.util.CommonConfig;
import com.shundr.common.view.DialogCall;
import com.shundr.frame.constant.LContext;
import com.shundr.user.CreditsActivity;
import com.shundr.user.LoginActivity;

/**
 * 
 * ToolFragment 工具箱
 * 
 * @author larry 2015-6-24 上午9:39:54 
 * @version 1.0.0
 *
 */
public class ToolFragment extends BaseFragment {

	private View mView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.fragment_tool, null);//
		initView(mView);
		return mView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}
	
	private void initView(View view) {
		
		view.findViewById(R.id.layout_tool_nearby).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				new CommonRequest(mContext, new Handler()).saveOperateHistory(0, CommonConfig.OPERATE_OBJECT_TOOL, CommonConfig.OPERATE_SERVICE, "使用了生活服务功能");
				Intent intent = new Intent(mContext, CommonWebViewActivity.class);
				intent.putExtra("url", "http://map.baidu.com/");
				intent.putExtra("title", "生活服务");
				startActivity(intent);
			}
		});
		
		view.findViewById(R.id.layout_tool_illegal).setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						new CommonRequest(mContext, new Handler()).saveOperateHistory(0, CommonConfig.OPERATE_OBJECT_TOOL, CommonConfig.OPERATE_ILLEGAL, "使用了违章查询功能");
						Intent intent = new Intent(mContext, CommonWebViewActivity.class);
						intent.putExtra("url", "http://map.baidu.com/mobile/webapp/third/peccancy/");
						intent.putExtra("title", "违章查询");
						startActivity(intent);
					}
				});

		view.findViewById(R.id.layout_tool_service).setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						DialogCall callDialog = new DialogCall(mContext);
						callDialog.show();
					}
				});
		view.findViewById(R.id.layout_tool_game).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				new CommonRequest(mContext, new Handler()).saveOperateHistory(0, CommonConfig.OPERATE_OBJECT_TOOL, CommonConfig.OPERATE_GAME, "使用了休闲娱乐功能");
				Intent intent = new Intent(mContext, CommonWebViewActivity.class);
				intent.putExtra("url", "http://h5.gamedog.cn/");
				intent.putExtra("title", "休闲娱乐");
				startActivity(intent);
			}
		});
		view.findViewById(R.id.layout_tool_invitation).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				//邀请
				if(LContext.isLogin()){
					Intent intent = new Intent(mContext, InvitationActivity.class);
					startActivity(intent);
				}else{
					startActivityForResult(new Intent(getActivity(), LoginActivity.class), 500);
				}
			}
		});
		view.findViewById(R.id.layout_main_wallet).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				//积分查询
				if(LContext.isLogin()){
					Intent intent = new Intent(mContext, CreditsActivity.class);
					startActivity(intent);
				}else{
					startActivityForResult(new Intent(getActivity(), LoginActivity.class), 500);
				}
			}
		});
		
	}

	
	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

}
